package coroutines

import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.runBlocking

@ExperimentalCoroutinesApi
fun main(){
    runBlocking {
        val nums = (1..3).asFlow().onEach { delay(300) }
        val strs = flowOf("one", "two", "three").onEach { delay(400) }
        val startime = System.currentTimeMillis()
        //每当上游流产生值的时候都会重新计算，这里两个流只要产生了值就会调用一下
        nums.combine(strs) { a, b -> "$a -> $b" }
            .collect {value->
                println("$value at ${System.currentTimeMillis() - startime} ms from start")
            }
    }
}